package com.spzx.user.service.impl;

import java.util.List;
import java.util.Arrays;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.common.core.utils.DateUtils;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.user.domain.UserAddress;
import com.spzx.user.domain.UserRegisterDTO;
import com.spzx.user.mapper.UserAddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.spzx.user.mapper.UserInfoMapper;
import com.spzx.user.domain.UserInfo;
import com.spzx.user.service.IUserInfoService;

/**
 * 会员Service业务层处理
 *
 * @author atguigu
 * @date 2024-09-29
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements IUserInfoService
{
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private UserAddressMapper userAddressMapper;

    /**
     * 查询会员列表
     *
     * @param userInfo 会员
     * @return 会员
     */
    @Override
    public List<UserInfo> selectUserInfoList(UserInfo userInfo)
    {
        return userInfoMapper.selectUserInfoList(userInfo);
    }

    @Override
    public List<UserAddress> selectAddressList(Long id) {
        System.out.println(id);
        return userAddressMapper.selectList(new LambdaQueryWrapper<UserAddress>().eq(UserAddress::getUserId,id));
    }

    @Override
    public void saveUserInfo(UserRegisterDTO userRegisterDTO) {

        UserInfo userInfo = new UserInfo();
        userInfo.setUsername(userRegisterDTO.getUsername());
        userInfo.setPassword(SecurityUtils.encryptPassword(userRegisterDTO
                .getPassword()));
        userInfo.setNickName(userRegisterDTO.getNickName());
        userInfo.setPhone(userRegisterDTO.getUsername());

        userInfo.setAvatar("https://himg.bdimg.com/sys/portraitn/item/public.1.e549800e.6xM5oiUa2-LAKza-rYAJVw");
        userInfo.setSex(1);
        userInfo.setStatus(1);

        baseMapper.insert(userInfo);

    }

}
